package com.gukun.springboot.tdengine.controller;

import com.gukun.springboot.tdengine.domain.common.CommonResult;
import com.gukun.springboot.tdengine.dto.CreateTableDto;
import com.gukun.springboot.tdengine.dto.TDengineConfigDto;
import com.gukun.springboot.tdengine.dto.WriteRulesDto;
import com.gukun.springboot.tdengine.service.TDEngineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/rtdb/api/tdengine/write")
@RestController
public class TDengineWriteController {
    private static final Logger logger = LoggerFactory.getLogger(RtdbController.class);

    @Autowired
    private TDEngineService tdEngineService;

    /**
     * 初始化数据库
     *
     * @return 建库信息
     */
    @Operation(summary = "初始化数据库", description = "新建TDengine数据库")
    @PostMapping("/initTdengineDatbase")
    public CommonResult<String> initTdengineDatbase(@RequestBody(description = "新建数据库的参数") @org.springframework.web.bind.annotation.RequestBody TDengineConfigDto
                                                               tDengineConfigDto) {
        return tdEngineService.initTdengineDatbase(tDengineConfigDto);
    }

    /**
     * 执行建表（包括四张超级表的添加）
     *
     * @return 建表信息
     */
    @Operation(summary = "执行建表", description = "新建TDengine数据库对应的表信息")
    @PostMapping("/createTdengineTables")
    public CommonResult<String> createTdengineTables(@RequestBody(description = "执行建表") @org.springframework.web.bind.annotation.RequestBody CreateTableDto
                                                            createTableDto) {
        return tdEngineService.createTdengineTables(createTableDto);
    }

    /**
     * 历史数据写入执行
     *
     * @return 模拟数据写入执行
     */
    @Operation(summary = "模拟数据写入执行", description = "新建TDengine数据库对应的表数据添加")
    @PostMapping("/beginTDengineWrite")
    public CommonResult<String> beginTDengineWrite(@RequestBody(description = "模拟数据写入执行") @org.springframework.web.bind.annotation.RequestBody WriteRulesDto
                                                             writeRulesDto) {
        return tdEngineService.beginTDengineWrite(writeRulesDto,null,"");
    }

    /**
     * 停止模拟数据写入
     *
     * @return 停止模拟数据写入
     */
    @Operation(summary = "停止模拟数据写入", description = "停止模拟数据写入")
    @PostMapping("/stopTDengineWrite")
    public CommonResult<String> stopTDengineWrite(@RequestBody(description = "模拟数据写入执行") @org.springframework.web.bind.annotation.RequestBody CreateTableDto
                                                              createTableDto) {
        return tdEngineService.stopTDengineWrite(createTableDto,null);
    }

    /**
     * 判断写入任务是否存在
     *
     * @return 0表示不存在    1表示存在
     */
    @Operation(summary = "判断写入任务是否存在", description = "判断写入任务是否存在")
    @PostMapping("/getTDengineWriteStatus")
    public CommonResult<Integer> getTDengineWriteStatus(@RequestBody(description = "判断写入任务是否存在") @org.springframework.web.bind.annotation.RequestBody CreateTableDto
                                                          createTableDto) {
        return tdEngineService.getTDengineWriteStatus(createTableDto,null);
    }


}
